from flask_wtf import FlaskForm
from flask_wtf.file import FileField, FileAllowed
from wtforms.fields.choices import SelectField
from wtforms.fields.simple import SubmitField, TextAreaField
from wtforms.validators import DataRequired, Length

IMG_ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif'}
IMG_ALLOWED_MESSAGE='只允许上传图片文件 (JPG, JPEG, PNG, GIF)'

class PostForm(FlaskForm):
    img = FileField('选择文件', validators=[
        FileAllowed(IMG_ALLOWED_EXTENSIONS,IMG_ALLOWED_MESSAGE)
    ])

    text = TextAreaField('用户名', validators=[
        DataRequired(message="帖子内容不能为空"),
        Length(min=5, message="帖子内容至少五个字")
    ])

    sort = SelectField('选择一个选项', choices=[
        ('', '请选择'),
        ('交友', '交友'),
        ('交易', '交易'),
        ('咨询', '咨询')
    ], validators=[DataRequired(message='必须选择一个选项')])

    submit = SubmitField('上传')